package com.dupt.web.controller.assemble;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dupt.common.annotation.Log;
import com.dupt.common.core.controller.BaseController;
import com.dupt.common.core.domain.AjaxResult;
import com.dupt.common.enums.BusinessType;
import com.dupt.system.domain.ProductLibrary;
import com.dupt.system.service.IProductLibraryService;
import com.dupt.common.utils.poi.ExcelUtil;
import com.dupt.common.core.page.TableDataInfo;

/**
 * 产品库Controller
 * 
 * @author zhuanyu.sun
 * @date 2025-07-10
 */
@RestController
@RequestMapping("/system/library")
public class ProductLibraryController extends BaseController
{
    @Autowired
    private IProductLibraryService productLibraryService;

    /**
     * 查询产品库列表
     */
    @PreAuthorize("@ss.hasPermi('system:library:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductLibrary productLibrary)
    {
        startPage();
        List<ProductLibrary> list = productLibraryService.selectProductLibraryList(productLibrary);
        return getDataTable(list);
    }

    /**
     * 导出产品库列表
     */
    @PreAuthorize("@ss.hasPermi('system:library:export')")
    @Log(title = "产品库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductLibrary productLibrary)
    {
        List<ProductLibrary> list = productLibraryService.selectProductLibraryList(productLibrary);
        ExcelUtil<ProductLibrary> util = new ExcelUtil<ProductLibrary>(ProductLibrary.class);
        util.exportExcel(response, list, "产品库数据");
    }

    /**
     * 获取产品库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:library:query')")
    @GetMapping(value = "/{productLibraryId}")
    public AjaxResult getInfo(@PathVariable("productLibraryId") Long productLibraryId)
    {
        return success(productLibraryService.selectProductLibraryByProductLibraryId(productLibraryId));
    }

    /**
     * 新增产品库
     */
    @PreAuthorize("@ss.hasPermi('system:library:add')")
    @Log(title = "产品库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductLibrary productLibrary)
    {
        return toAjax(productLibraryService.insertProductLibrary(productLibrary));
    }

    /**
     * 修改产品库
     */
    @PreAuthorize("@ss.hasPermi('system:library:edit')")
    @Log(title = "产品库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductLibrary productLibrary)
    {
        return toAjax(productLibraryService.updateProductLibrary(productLibrary));
    }

    /**
     * 删除产品库
     */
    @PreAuthorize("@ss.hasPermi('system:library:remove')")
    @Log(title = "产品库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productLibraryIds}")
    public AjaxResult remove(@PathVariable Long[] productLibraryIds)
    {
        return toAjax(productLibraryService.deleteProductLibraryByProductLibraryIds(productLibraryIds));
    }
}
